package com.situ.controller.product;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.product.ProductService;
import com.situ.entity.product.Product;
import com.situ.util.*;
/**
 * Product的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class ProductController {

	/** ProductService服务 */
	@Autowired
	private ProductService productService;
	
	/**
	 * 查询所有Product数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/Product/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(Product value) {

		return ResponseData.ok().putDataValue("list",productService.find(value));
	}
	
	/**
	 * 通过id查询Product数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/Product/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") Long id) {
		 return ResponseData.ok().putDataValue("obj",productService.findOne(id));
	}
	
	/**
	 * 插入Product属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/Product/save")
	public ResponseData save(Product value) {
		return ResponseData.ok().putDataValue("obj", productService.saveNotNull(value));
	}
	
	/**
	 * 更新Product属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/Product/update", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(Product value) {
		return ResponseData.ok().putDataValue("obj",productService.updateNotNullById(value));
	}

	/**
	 * 通过id删除Product数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/Product/delById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delById(@PathVariable(name="id") Long id) {
		return ResponseData.ok().putDataValue("obj",productService.deleteById(id));
	}


    //带分页的查询全部
//@ApiOperation("带分页的查询全部")
/*
    @RequestMapping(value = "/Product/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(Product value,
                             @RequestParam(defaultValue = "1",required = false) int pageNum ,
                             @RequestParam(defaultValue = "5",required = false) int pageSize) {

	    PageHelper.startPage(pageNum, pageSize);
        List<SysMight> list = sysMightService.find2(value);
    PageInfo pageInfo = new PageInfo<SysMight>(list,5);

        return ResponseData.ok()
        // .putDataValue("list", list)
        .putDataValue("pageInfo",pageInfo);
        }
 */
}
